package com.hzhr.iot.cqgas.ds.controller;

import com.hzhr.iot.core.util.HzhrDateUtil;
import com.hzhr.iot.core.util.HzhrTypeUtil;
import com.hzhr.iot.cqgas.ds.dao.device.custom.DevCollectDeviceCustomDao;
import com.hzhr.iot.cqgas.ds.dao.device.custom.DeviceDao;
import com.hzhr.iot.cqgas.ds.dao.device.example.DevCollectDeviceDao;
import com.hzhr.iot.cqgas.ds.dao.device.example.DevIotDeviceDao;
import com.hzhr.iot.cqgas.ds.dao.statis.custom.StatisDao;
import com.hzhr.iot.cqgas.ds.dao.toll.custom.TollGasUserCustomDao;
import com.hzhr.iot.cqgas.ds.dao.toll.example.TollGasUserDao;
import com.hzhr.iot.cqgas.ds.dao.user.custom.UserCustomDao;
import com.hzhr.iot.cqgas.ds.dao.user.example.UsrDeptDao;
import com.hzhr.iot.cqgas.ds.entity.device.DevCollectDeviceEntity;
import com.hzhr.iot.cqgas.ds.entity.device.DevCollectDeviceExample;
import com.hzhr.iot.cqgas.ds.entity.device.dto.DevCollectDeviceEntityDto;
import com.hzhr.iot.cqgas.ds.entity.toll.TollGasUserEntity;
import com.hzhr.iot.cqgas.ds.entity.toll.dto.TollGasUserEntityDto;
import com.hzhr.iot.cqgas.ds.entity.user.UsrDeptEntity;
import com.hzhr.iot.cqgas.ds.service.StatisService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;
import java.util.concurrent.Future;

@RestController
public class StatisController {
    @Autowired
    DevIotDeviceDao devIotDeviceDao;
    @Autowired
    DevCollectDeviceDao devCollectDeviceDao;
    @Autowired
    StatisService statisService;
    @Autowired
    TollGasUserDao tollGasUserDao;
    @Autowired
    UsrDeptDao usrDeptDao;
    @Autowired
    DevCollectDeviceCustomDao devCollectDeviceCustomDao;
    @Autowired
    UserCustomDao userCustomDao;
    @Autowired
    TollGasUserCustomDao tollGasUserCustomDao;
    @Autowired
    StatisDao statisDao;
    @Autowired
    DeviceDao deviceDao;

    private Logger logger = LoggerFactory.getLogger(StatisController.class);

    @RequestMapping(value = "/syncDeviceStatis_day")
    public void syncDeviceStatis_day() throws Exception {
        long start = new Date().getTime();

        Map<String, Integer> logMap = new HashMap<>();
        logMap.put("deviceDailyGasConsumeUpdateCount", 0);
        logMap.put("deviceDailyGasConsumeInsertCount", 0);
        logMap.put("deviceMonthlyGasConsumeUpdateCount", 0);
        logMap.put("deviceMonthlyGasConsumeInsertCount", 0);

        int day = 1;

        //查询出采集设备
        List<DevCollectDeviceEntity> devCollectDeviceEntities = devCollectDeviceDao.selectByExample(new DevCollectDeviceExample());

        //同步数据
        List<Future<Map<String, Integer>>> lstFuture = new ArrayList<Future<Map<String, Integer>>>();// 存放所有的线程，用于获取结果
        for (int i = 1; i <= 10; i++) {
            Future<Map<String, Integer>> result = statisService.syncDeviceStatis(i, day, devCollectDeviceEntities);
            lstFuture.add(result);
        }

        for (Future<Map<String, Integer>> future : lstFuture) {// 获取值。get是阻塞式，等待当前线程完成才返回值
            int deviceDailyGasConsumeUpdateCount = logMap.get("deviceDailyGasConsumeUpdateCount");
            deviceDailyGasConsumeUpdateCount += future.get().get("deviceDailyGasConsumeUpdateCount");
            logMap.put("deviceDailyGasConsumeUpdateCount", deviceDailyGasConsumeUpdateCount);

            int deviceDailyGasConsumeInsertCount = logMap.get("deviceDailyGasConsumeInsertCount");
            deviceDailyGasConsumeInsertCount += future.get().get("deviceDailyGasConsumeInsertCount");
            logMap.put("deviceDailyGasConsumeInsertCount", deviceDailyGasConsumeInsertCount);

            int deviceMonthlyGasConsumeUpdateCount = logMap.get("deviceMonthlyGasConsumeUpdateCount");
            deviceMonthlyGasConsumeUpdateCount += future.get().get("deviceMonthlyGasConsumeUpdateCount");
            logMap.put("deviceMonthlyGasConsumeUpdateCount", deviceMonthlyGasConsumeUpdateCount);

            int deviceMonthlyGasConsumeInsertCount = logMap.get("deviceMonthlyGasConsumeInsertCount");
            deviceMonthlyGasConsumeInsertCount += future.get().get("deviceMonthlyGasConsumeInsertCount");
            logMap.put("deviceMonthlyGasConsumeInsertCount", deviceMonthlyGasConsumeInsertCount);
        }

        long end = new Date().getTime();
        logger.info("同步设备统计结束: ");
        logger.info("同步时间: " + (end - start) / 1000 + "s");
        logger.info("更新日统计数量: " + logMap.get("deviceDailyGasConsumeUpdateCount") + "条");
        logger.info("新增日统计数量: " + logMap.get("deviceDailyGasConsumeInsertCount") + "条");
        logger.info("更新月统计数量: " + logMap.get("deviceMonthlyGasConsumeUpdateCount") + "条");
        logger.info("新增月统计数量: " + logMap.get("deviceMonthlyGasConsumeInsertCount") + "条");
    }
    @RequestMapping(value = "/syncDeviceStatis_day_onlyDay")
    public void syncDeviceStatis_day_onlyDay() throws Exception {
        long start = (new Date()).getTime();

        Map<String, Integer> logMap = new HashMap<String, Integer>();
        logMap.put("deviceDailyGasConsumeUpdateCount", Integer.valueOf(0));
        logMap.put("deviceDailyGasConsumeInsertCount", Integer.valueOf(0));

        int day = 1;


        List<DevCollectDeviceEntityDto> devCollectDeviceEntities = deviceDao.select7();


        List<Integer> collectDeviceIds = this.statisDao.select1(HzhrDateUtil.dateToStr(HzhrDateUtil.addDay(HzhrDateUtil.getDayBegin(), -1)));
        List<DevCollectDeviceEntityDto> devCollectDeviceEntities1 = new ArrayList<>();

        for (DevCollectDeviceEntityDto devCollectDeviceEntity:
                devCollectDeviceEntities) {
            Integer collectDeviceId = devCollectDeviceEntity.getId();
            if (!collectDeviceIds.contains(collectDeviceId)) {
                devCollectDeviceEntities1.add(devCollectDeviceEntity);
            }
        }

        List<Future<Map<String, Integer>>> lstFuture = new ArrayList<>();
        for (int i = 1; i <= 10; i++) {
            Future<Map<String, Integer>> result = this.statisService.syncDeviceStatis_onlyDay(i, Integer.valueOf(day), devCollectDeviceEntities1);
            lstFuture.add(result);
        }

        for (Future<Map<String, Integer>> future : lstFuture) {
            int deviceDailyGasConsumeUpdateCount = ((Integer)logMap.get("deviceDailyGasConsumeUpdateCount")).intValue();
            deviceDailyGasConsumeUpdateCount += ((Integer)((Map)future.get()).get("deviceDailyGasConsumeUpdateCount")).intValue();
            logMap.put("deviceDailyGasConsumeUpdateCount", Integer.valueOf(deviceDailyGasConsumeUpdateCount));

            int deviceDailyGasConsumeInsertCount = ((Integer)logMap.get("deviceDailyGasConsumeInsertCount")).intValue();
            deviceDailyGasConsumeInsertCount += ((Integer)((Map)future.get()).get("deviceDailyGasConsumeInsertCount")).intValue();
            logMap.put("deviceDailyGasConsumeInsertCount", Integer.valueOf(deviceDailyGasConsumeInsertCount));
        }

        long end = new Date().getTime();
        logger.info("同步设备统计结束: ");
        logger.info("同步时间: " + (end - start) / 1000 + "s");
        logger.info("更新日统计数量: " + logMap.get("deviceDailyGasConsumeUpdateCount") + "条");
        logger.info("新增日统计数量: " + logMap.get("deviceDailyGasConsumeInsertCount") + "条");
    }
    @RequestMapping(value = "/syncDeviceStatis")
    public void syncDeviceStatis(@RequestParam("day") Integer day) throws Exception {
        long start = new Date().getTime();

        Map<String, Integer> logMap = new HashMap<>();
        logMap.put("deviceDailyGasConsumeUpdateCount", 0);
        logMap.put("deviceDailyGasConsumeInsertCount", 0);
        logMap.put("deviceMonthlyGasConsumeUpdateCount", 0);
        logMap.put("deviceMonthlyGasConsumeInsertCount", 0);

        if (day == null) day = 7;

        //查询出采集设备
        List<DevCollectDeviceEntity> devCollectDeviceEntities = devCollectDeviceDao.selectByExample(new DevCollectDeviceExample());

        //同步数据
        List<Future<Map<String, Integer>>> lstFuture = new ArrayList<Future<Map<String, Integer>>>();// 存放所有的线程，用于获取结果
        for (int i = 1; i <= 10; i++) {
            Future<Map<String, Integer>> result = statisService.syncDeviceStatis(i, day, devCollectDeviceEntities);
            lstFuture.add(result);
        }

        for (Future<Map<String, Integer>> future : lstFuture) {// 获取值。get是阻塞式，等待当前线程完成才返回值
            int deviceDailyGasConsumeUpdateCount = logMap.get("deviceDailyGasConsumeUpdateCount");
            deviceDailyGasConsumeUpdateCount += future.get().get("deviceDailyGasConsumeUpdateCount");
            logMap.put("deviceDailyGasConsumeUpdateCount", deviceDailyGasConsumeUpdateCount);

            int deviceDailyGasConsumeInsertCount = logMap.get("deviceDailyGasConsumeInsertCount");
            deviceDailyGasConsumeInsertCount += future.get().get("deviceDailyGasConsumeInsertCount");
            logMap.put("deviceDailyGasConsumeInsertCount", deviceDailyGasConsumeInsertCount);

            int deviceMonthlyGasConsumeUpdateCount = logMap.get("deviceMonthlyGasConsumeUpdateCount");
            deviceMonthlyGasConsumeUpdateCount += future.get().get("deviceMonthlyGasConsumeUpdateCount");
            logMap.put("deviceMonthlyGasConsumeUpdateCount", deviceMonthlyGasConsumeUpdateCount);

            int deviceMonthlyGasConsumeInsertCount = logMap.get("deviceMonthlyGasConsumeInsertCount");
            deviceMonthlyGasConsumeInsertCount += future.get().get("deviceMonthlyGasConsumeInsertCount");
            logMap.put("deviceMonthlyGasConsumeInsertCount", deviceMonthlyGasConsumeInsertCount);
        }

        long end = new Date().getTime();
        logger.info("同步设备统计结束: ");
        logger.info("同步时间: " + (end - start) / 1000 + "s");
        logger.info("更新日统计数量: " + logMap.get("deviceDailyGasConsumeUpdateCount") + "条");
        logger.info("新增日统计数量: " + logMap.get("deviceDailyGasConsumeInsertCount") + "条");
        logger.info("更新月统计数量: " + logMap.get("deviceMonthlyGasConsumeUpdateCount") + "条");
        logger.info("新增月统计数量: " + logMap.get("deviceMonthlyGasConsumeInsertCount") + "条");
    }

    @RequestMapping(value = "/syncGasUserStatis_day")
    public void syncGasUserStatis_day() throws Exception {
        long start = new Date().getTime();

        Map<String, Integer> logMap = new HashMap<>();
        logMap.put("gasUserDailyGasConsumeUpdateCount", 0);
        logMap.put("gasUserDailyGasConsumeInsertCount", 0);
        logMap.put("gasUserMonthlyGasConsumeUpdateCount", 0);
        logMap.put("gasUserMonthlyGasConsumeInsertCount", 0);

        int day = 1;

        //查询出燃气用户
        List<TollGasUserEntity> tollGasUserEntities = tollGasUserDao.selectByExample(null);

        //同步数据
        List<Future<Map<String, Integer>>> lstFuture = new ArrayList<Future<Map<String, Integer>>>();// 存放所有的线程，用于获取结果
        for (int i = 1; i <= 10; i++) {
            Future<Map<String, Integer>> result = statisService.syncGasUserStatis(i, day, tollGasUserEntities);
            lstFuture.add(result);
        }

        for (Future<Map<String, Integer>> future : lstFuture) {// 获取值。get是阻塞式，等待当前线程完成才返回值
            int gasUserDailyGasConsumeUpdateCount = logMap.get("gasUserDailyGasConsumeUpdateCount");
            gasUserDailyGasConsumeUpdateCount += future.get().get("gasUserDailyGasConsumeUpdateCount");
            logMap.put("gasUserDailyGasConsumeUpdateCount", gasUserDailyGasConsumeUpdateCount);

            int gasUserDailyGasConsumeInsertCount = logMap.get("gasUserDailyGasConsumeInsertCount");
            gasUserDailyGasConsumeInsertCount += future.get().get("gasUserDailyGasConsumeInsertCount");
            logMap.put("gasUserDailyGasConsumeInsertCount", gasUserDailyGasConsumeInsertCount);

            int gasUserMonthlyGasConsumeUpdateCount = logMap.get("gasUserMonthlyGasConsumeUpdateCount");
            gasUserMonthlyGasConsumeUpdateCount += future.get().get("gasUserMonthlyGasConsumeUpdateCount");
            logMap.put("gasUserMonthlyGasConsumeUpdateCount", gasUserMonthlyGasConsumeUpdateCount);

            int gasUserMonthlyGasConsumeInsertCount = logMap.get("gasUserMonthlyGasConsumeInsertCount");
            gasUserMonthlyGasConsumeInsertCount += future.get().get("gasUserMonthlyGasConsumeInsertCount");
            logMap.put("gasUserMonthlyGasConsumeInsertCount", gasUserMonthlyGasConsumeInsertCount);
        }

        long end = new Date().getTime();
        logger.info("同步燃气用户统计结束: ");
        logger.info("同步时间: " + (end - start) / 1000 + "s");
        logger.info("更新日统计数量: " + logMap.get("gasUserDailyGasConsumeUpdateCount") + "条");
        logger.info("新增日统计数量: " + logMap.get("gasUserDailyGasConsumeInsertCount") + "条");
        logger.info("更新月统计数量: " + logMap.get("gasUserMonthlyGasConsumeUpdateCount") + "条");
        logger.info("新增月统计数量: " + logMap.get("gasUserMonthlyGasConsumeInsertCount") + "条");
    }
    @RequestMapping(value = "/syncGasUserStatis_day_onlyDay")
    public void syncGasUserStatis_day_onlyDay() throws Exception {
        long start = (new Date()).getTime();

        Map<String, Integer> logMap = new HashMap<String, Integer>();
        logMap.put("gasUserDailyGasConsumeUpdateCount", Integer.valueOf(0));
        logMap.put("gasUserDailyGasConsumeInsertCount", Integer.valueOf(0));

        int day = 1;


        List<TollGasUserEntityDto> tollGasUserEntities = tollGasUserCustomDao.select2();


        List<Integer> gasUserIds = this.statisDao.select2(HzhrDateUtil.dateToStr(HzhrDateUtil.addDay(HzhrDateUtil.getDayBegin(), -1)));
        List<TollGasUserEntityDto> tollGasUserEntities1 = new ArrayList<>();

        for (TollGasUserEntityDto tollGasUserEntity :
                tollGasUserEntities) {
            Integer gasUserId = tollGasUserEntity.getId();
            if (!gasUserIds.contains(gasUserId)) {
                tollGasUserEntities1.add(tollGasUserEntity);
            }
        }



        List<Future<Map<String, Integer>>> lstFuture = new ArrayList<Future<Map<String, Integer>>>();
        for (int i = 1; i <= 10; i++) {
            Future<Map<String, Integer>> result = this.statisService.syncGasUserStatis_onlyDay(i, Integer.valueOf(day), tollGasUserEntities1);
            lstFuture.add(result);
        }

        for (Future<Map<String, Integer>> future : lstFuture) {
            int gasUserDailyGasConsumeUpdateCount = ((Integer)logMap.get("gasUserDailyGasConsumeUpdateCount")).intValue();
            gasUserDailyGasConsumeUpdateCount += ((Integer)((Map)future.get()).get("gasUserDailyGasConsumeUpdateCount")).intValue();
            logMap.put("gasUserDailyGasConsumeUpdateCount", Integer.valueOf(gasUserDailyGasConsumeUpdateCount));

            int gasUserDailyGasConsumeInsertCount = ((Integer)logMap.get("gasUserDailyGasConsumeInsertCount")).intValue();
            gasUserDailyGasConsumeInsertCount += ((Integer)((Map)future.get()).get("gasUserDailyGasConsumeInsertCount")).intValue();
            logMap.put("gasUserDailyGasConsumeInsertCount", Integer.valueOf(gasUserDailyGasConsumeInsertCount));
        }

        long end = new Date().getTime();
        logger.info("同步燃气用户统计结束: ");
        logger.info("同步时间: " + (end - start) / 1000 + "s");
        logger.info("更新日统计数量: " + logMap.get("gasUserDailyGasConsumeUpdateCount") + "条");
        logger.info("新增日统计数量: " + logMap.get("gasUserDailyGasConsumeInsertCount") + "条");
    }
    @RequestMapping(value = "/syncGasUserStatis")
    public void syncGasUserStatis(@RequestParam("day") Integer day) throws Exception {
        long start = new Date().getTime();

        Map<String, Integer> logMap = new HashMap<>();
        logMap.put("gasUserDailyGasConsumeUpdateCount", 0);
        logMap.put("gasUserDailyGasConsumeInsertCount", 0);
        logMap.put("gasUserMonthlyGasConsumeUpdateCount", 0);
        logMap.put("gasUserMonthlyGasConsumeInsertCount", 0);

        if (day == null) day = 7;

        //查询出燃气用户
        List<TollGasUserEntity> tollGasUserEntities = tollGasUserDao.selectByExample(null);

        //同步数据
        List<Future<Map<String, Integer>>> lstFuture = new ArrayList<Future<Map<String, Integer>>>();// 存放所有的线程，用于获取结果
        for (int i = 1; i <= 10; i++) {
            Future<Map<String, Integer>> result = statisService.syncGasUserStatis(i, day, tollGasUserEntities);
            lstFuture.add(result);
        }

        for (Future<Map<String, Integer>> future : lstFuture) {// 获取值。get是阻塞式，等待当前线程完成才返回值
            int gasUserDailyGasConsumeUpdateCount = logMap.get("gasUserDailyGasConsumeUpdateCount");
            gasUserDailyGasConsumeUpdateCount += future.get().get("gasUserDailyGasConsumeUpdateCount");
            logMap.put("gasUserDailyGasConsumeUpdateCount", gasUserDailyGasConsumeUpdateCount);

            int gasUserDailyGasConsumeInsertCount = logMap.get("gasUserDailyGasConsumeInsertCount");
            gasUserDailyGasConsumeInsertCount += future.get().get("gasUserDailyGasConsumeInsertCount");
            logMap.put("gasUserDailyGasConsumeInsertCount", gasUserDailyGasConsumeInsertCount);

            int gasUserMonthlyGasConsumeUpdateCount = logMap.get("gasUserMonthlyGasConsumeUpdateCount");
            gasUserMonthlyGasConsumeUpdateCount += future.get().get("gasUserMonthlyGasConsumeUpdateCount");
            logMap.put("gasUserMonthlyGasConsumeUpdateCount", gasUserMonthlyGasConsumeUpdateCount);

            int gasUserMonthlyGasConsumeInsertCount = logMap.get("gasUserMonthlyGasConsumeInsertCount");
            gasUserMonthlyGasConsumeInsertCount += future.get().get("gasUserMonthlyGasConsumeInsertCount");
            logMap.put("gasUserMonthlyGasConsumeInsertCount", gasUserMonthlyGasConsumeInsertCount);
        }

        long end = new Date().getTime();
        logger.info("同步燃气用户统计结束: ");
        logger.info("同步时间: " + (end - start) / 1000 + "s");
        logger.info("更新日统计数量: " + logMap.get("gasUserDailyGasConsumeUpdateCount") + "条");
        logger.info("新增日统计数量: " + logMap.get("gasUserDailyGasConsumeInsertCount") + "条");
        logger.info("更新月统计数量: " + logMap.get("gasUserMonthlyGasConsumeUpdateCount") + "条");
        logger.info("新增月统计数量: " + logMap.get("gasUserMonthlyGasConsumeInsertCount") + "条");
    }

    @RequestMapping(value = "/syncDeptStatis_day")
    public void syncDeptStatis_day() throws Exception {
        long start = new Date().getTime();

        Map<String, Integer> logMap = new HashMap<>();
        logMap.put("deptDailyGasConsumeUpdateCount", 0);
        logMap.put("deptDailyGasConsumeInsertCount", 0);
        logMap.put("deptMonthlyGasConsumeUpdateCount", 0);
        logMap.put("deptMonthlyGasConsumeInsertCount", 0);

        int day = 1;

        //查询出燃气用户
        List<UsrDeptEntity> usrDeptEntities = usrDeptDao.selectByExample(null);

        //同步数据
        List<Future<Map<String, Integer>>> lstFuture = new ArrayList<Future<Map<String, Integer>>>();// 存放所有的线程，用于获取结果
        Future<Map<String, Integer>> result = statisService.syncDeptStatis(day, usrDeptEntities);
        lstFuture.add(result);

        for (Future<Map<String, Integer>> future : lstFuture) {// 获取值。get是阻塞式，等待当前线程完成才返回值
            int deptDailyGasConsumeUpdateCount = logMap.get("deptDailyGasConsumeUpdateCount");
            deptDailyGasConsumeUpdateCount += future.get().get("deptDailyGasConsumeUpdateCount");
            logMap.put("deptDailyGasConsumeUpdateCount", deptDailyGasConsumeUpdateCount);

            int deptDailyGasConsumeInsertCount = logMap.get("deptDailyGasConsumeInsertCount");
            deptDailyGasConsumeInsertCount += future.get().get("deptDailyGasConsumeInsertCount");
            logMap.put("deptDailyGasConsumeInsertCount", deptDailyGasConsumeInsertCount);

            int deptMonthlyGasConsumeUpdateCount = logMap.get("deptMonthlyGasConsumeUpdateCount");
            deptMonthlyGasConsumeUpdateCount += future.get().get("deptMonthlyGasConsumeUpdateCount");
            logMap.put("deptMonthlyGasConsumeUpdateCount", deptMonthlyGasConsumeUpdateCount);

            int deptMonthlyGasConsumeInsertCount = logMap.get("deptMonthlyGasConsumeInsertCount");
            deptMonthlyGasConsumeInsertCount += future.get().get("deptMonthlyGasConsumeInsertCount");
            logMap.put("deptMonthlyGasConsumeInsertCount", deptMonthlyGasConsumeInsertCount);
        }

        long end = new Date().getTime();
        logger.info("同步部门统计结束: ");
        logger.info("同步时间: " + (end - start) / 1000 + "s");
        logger.info("更新日统计数量: " + logMap.get("deptDailyGasConsumeUpdateCount") + "条");
        logger.info("新增日统计数量: " + logMap.get("deptDailyGasConsumeInsertCount") + "条");
        logger.info("更新月统计数量: " + logMap.get("deptMonthlyGasConsumeUpdateCount") + "条");
        logger.info("新增月统计数量: " + logMap.get("deptMonthlyGasConsumeInsertCount") + "条");
    }
    @RequestMapping(value = "/syncDeptStatis")
    public void syncDeptStatis(@RequestParam("day") Integer day) throws Exception {
        long start = new Date().getTime();

        Map<String, Integer> logMap = new HashMap<>();
        logMap.put("deptDailyGasConsumeUpdateCount", 0);
        logMap.put("deptDailyGasConsumeInsertCount", 0);
        logMap.put("deptMonthlyGasConsumeUpdateCount", 0);
        logMap.put("deptMonthlyGasConsumeInsertCount", 0);

        if (day == null) day = 7;

        //查询出燃气用户
        List<UsrDeptEntity> usrDeptEntities = usrDeptDao.selectByExample(null);

        //同步数据
        List<Future<Map<String, Integer>>> lstFuture = new ArrayList<Future<Map<String, Integer>>>();// 存放所有的线程，用于获取结果
        Future<Map<String, Integer>> result = statisService.syncDeptStatis(day, usrDeptEntities);
        lstFuture.add(result);

        for (Future<Map<String, Integer>> future : lstFuture) {// 获取值。get是阻塞式，等待当前线程完成才返回值
            int deptDailyGasConsumeUpdateCount = logMap.get("deptDailyGasConsumeUpdateCount");
            deptDailyGasConsumeUpdateCount += future.get().get("deptDailyGasConsumeUpdateCount");
            logMap.put("deptDailyGasConsumeUpdateCount", deptDailyGasConsumeUpdateCount);

            int deptDailyGasConsumeInsertCount = logMap.get("deptDailyGasConsumeInsertCount");
            deptDailyGasConsumeInsertCount += future.get().get("deptDailyGasConsumeInsertCount");
            logMap.put("deptDailyGasConsumeInsertCount", deptDailyGasConsumeInsertCount);

            int deptMonthlyGasConsumeUpdateCount = logMap.get("deptMonthlyGasConsumeUpdateCount");
            deptMonthlyGasConsumeUpdateCount += future.get().get("deptMonthlyGasConsumeUpdateCount");
            logMap.put("deptMonthlyGasConsumeUpdateCount", deptMonthlyGasConsumeUpdateCount);

            int deptMonthlyGasConsumeInsertCount = logMap.get("deptMonthlyGasConsumeInsertCount");
            deptMonthlyGasConsumeInsertCount += future.get().get("deptMonthlyGasConsumeInsertCount");
            logMap.put("deptMonthlyGasConsumeInsertCount", deptMonthlyGasConsumeInsertCount);
        }

        long end = new Date().getTime();
        logger.info("同步部门统计结束: ");
        logger.info("同步时间: " + (end - start) / 1000 + "s");
        logger.info("更新日统计数量: " + logMap.get("deptDailyGasConsumeUpdateCount") + "条");
        logger.info("新增日统计数量: " + logMap.get("deptDailyGasConsumeInsertCount") + "条");
        logger.info("更新月统计数量: " + logMap.get("deptMonthlyGasConsumeUpdateCount") + "条");
        logger.info("新增月统计数量: " + logMap.get("deptMonthlyGasConsumeInsertCount") + "条");
    }

    @RequestMapping(value = "/syncDeviceDataException")
    public void syncDeviceDataException() throws Exception {
        long start = new Date().getTime();

        Map<String, Integer> logMap = new HashMap<>();
        logMap.put("wscCount", 0);
        logMap.put("wyqCount", 0);

        //查询设备信息
        List<Map<String, Object>> devices = devCollectDeviceCustomDao.select1();

        //补充冗余信息
        List<Map<String, Object>> depts = userCustomDao.select1();
        List<Map<String, Object>> companys = userCustomDao.select2();
        for (Map<String, Object> device :
        devices) {
            Integer COLLECT_DEVICE_DEPT_ID = HzhrTypeUtil.object2integer(device.get("COLLECT_DEVICE_DEPT_ID"));
            Integer IOT_DEVICE_COMPANY_ID = HzhrTypeUtil.object2integer(device.get("IOT_DEVICE_COMPANY_ID"));

            for (Map<String, Object> dept :
            depts) {
                Integer id = HzhrTypeUtil.object2integer(dept.get("ID"));
                String name = HzhrTypeUtil.object2string(dept.get("NAME"));
                if (id.equals(COLLECT_DEVICE_DEPT_ID)) {
                    device.put("COLLECT_DEVICE_DEPT_NAME", name);
                    break;
                }
            }

            for (Map<String, Object> company :
                    companys) {
                Integer id = HzhrTypeUtil.object2integer(company.get("ID"));
                String name = HzhrTypeUtil.object2string(company.get("NAME"));
                if (id.equals(IOT_DEVICE_COMPANY_ID)) {
                    device.put("IOT_DEVICE_COMPANY_NAME", name);
                    break;
                }
            }
        }

        //同步数据
        List<Future<Map<String, Integer>>> lstFuture = new ArrayList<Future<Map<String, Integer>>>();// 存放所有的线程，用于获取结果
        Future<Map<String, Integer>> result = statisService.syncDeviceDataException(devices);
        lstFuture.add(result);

        for (Future<Map<String, Integer>> future : lstFuture) {// 获取值。get是阻塞式，等待当前线程完成才返回值
            int wscCount = logMap.get("wscCount");
            wscCount += future.get().get("wscCount");
            logMap.put("wscCount", wscCount);

            int wyqCount = logMap.get("wyqCount");
            wyqCount += future.get().get("wyqCount");
            logMap.put("wyqCount", wyqCount);
        }

        long end = new Date().getTime();
        logger.info("同步设备 数据异常结束: ");
        logger.info("同步时间: " + (end - start) / 1000 + "s");
        logger.info("更新未上传数量: " + logMap.get("wscCount") + "条");
        logger.info("新增未用气数量: " + logMap.get("wyqCount") + "条");
    }

    @RequestMapping(value = "/syncDeviceDataStatisException")
    public void syncDeviceDataStatisException() throws Exception {
        List<Integer> ids = deviceDao.select15();
        for (Integer id :
        ids) {
            while (true) {
                Map<String, Object> map = statisDao.select3(id);
                if (map == null) break;
                Integer count = HzhrTypeUtil.object2integer(map.get("C"));
                Double per = HzhrTypeUtil.object2double(map.get("P"));
                Double max = HzhrTypeUtil.object2double(map.get("M"));
                Double sub = HzhrTypeUtil.object2double(map.get("S"));

                boolean updateFlag = false;
                if (per != null && count > 2 && max > 10) {
                    if (per >= 50) {
                        int changeCount = statisDao.update1(id, null, null);
                        if (changeCount > 0) {
                            updateFlag = true;
                        }
                    }
                    if (!updateFlag && per > 20 && sub > 500) {
                        int changeCount = statisDao.update1(id, null, null);
                        if (changeCount > 0) {
                            updateFlag = true;
                        }
                    }
                    if (!updateFlag && count > 10 && per >= 5 && max >= 100) {
                        int changeCount = statisDao.update1(id, null, null);
                        if (changeCount > 0) {
                            updateFlag = true;
                        }
                    }
                }

                if (!updateFlag) break;
            }
        }
    }
    @RequestMapping(value = "/syncDeviceDataStatisException_day")
    public void syncDeviceDataStatisException_day() throws Exception {
        List<Integer> ids = deviceDao.select15();
        for (Integer id :
                ids) {
            while (true) {
                Map<String, Object> map = statisDao.select3(id);
                if (map == null) break;
                Integer count = HzhrTypeUtil.object2integer(map.get("C"));
                Double per = HzhrTypeUtil.object2double(map.get("P"));
                Double max = HzhrTypeUtil.object2double(map.get("M"));
                Double sub = HzhrTypeUtil.object2double(map.get("S"));

                boolean updateFlag = false;
                if (per != null && count > 2 && max > 10) {
                    if (per >= 50) {
                        int changeCount = statisDao.update1(id, HzhrDateUtil.dateToStr(HzhrDateUtil.addDay(HzhrDateUtil.getDayBegin(), -1)), null);
                        if (changeCount > 0) {
                            updateFlag = true;
                        }
                    }
                    if (!updateFlag && per > 20 && sub > 500) {
                        int changeCount = statisDao.update1(id, HzhrDateUtil.dateToStr(HzhrDateUtil.addDay(HzhrDateUtil.getDayBegin(), -1)), null);
                        if (changeCount > 0) {
                            updateFlag = true;
                        }
                    }
                    if (!updateFlag && count > 10 && per >= 5 && max >= 100) {
                        int changeCount = statisDao.update1(id, HzhrDateUtil.dateToStr(HzhrDateUtil.addDay(HzhrDateUtil.getDayBegin(), -1)), null);
                        if (changeCount > 0) {
                            updateFlag = true;
                        }
                    }
                }

                if (!updateFlag) break;
            }
        }
    }


}
